package com.jin.boot.interceptor;

import org.apache.ibatis.executor.statement.StatementHandler;
import org.apache.ibatis.plugin.*;
import org.springframework.stereotype.Component;

import java.sql.Connection;
import java.util.Properties;

/**
 * @Description
 * @Author lijing1@wxchina.com
 * @Date 2020/11/26 15:09
 **/
@Intercepts({
        @Signature(method = "prepare", type = StatementHandler.class, args = { Connection.class, Integer.class }) })
@Component("customIntercepotr")
public class CustomIntercepotr  implements Interceptor {


    @Override
    public Object intercept(Invocation invocation) throws Throwable {
       /* StatementHandler ms = (StatementHandler) invocation.getTarget();
        String orignalSql= ms.getBoundSql().getSql();
        BoundSql boundSql= ms.getBoundSql();
        String newSql=orignalSql+" limit 2";
        Field field = boundSql.getClass().getDeclaredField("sql");
        ReflectionUtils.makeAccessible(field);
        ReflectionUtils.setField(field,boundSql,newSql);*/
        return invocation.proceed();
    }

    @Override
    public Object plugin(Object target) {
        return Plugin.wrap(target, this);
    }

    @Override
    public void setProperties(Properties properties) {

    }
}
